package com.travel.config;

import com.github.wxpay.sdk.WXPayConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.io.InputStream;

/**
 * @author chendikai
 * @date 2024-07-23 10:09
 */
@Configuration
public class WeChatPayConfig implements WXPayConfig {
    @Value("${pay-platform.wx.pay.appId}")
    private String appId;

    @Value("${pay-platform.wx.pay.mchId}")
    private String mchId;

    @Value("${pay-platform.wx.pay.mchKey}")
    private String mchKey;

    @Value("${pay-platform.wx.pay.certPath}")
    private String certPath;

    @Override
    public String getAppID() {
        return appId;
    }

    @Override
    public String getMchID() {
        return mchId;
    }

    @Override
    public String getKey() {
        return mchKey;
    }

    @Override
    public InputStream getCertStream() {
        // 若使用沙箱环境，则返回null
        return certPath == null ? null : getClass().getClassLoader().getResourceAsStream(certPath);
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }
}
